package com.yj.springbootdesign.observe;

import java.util.ArrayList;
import java.util.List;

/**
 * 被观察者对象
 */
public abstract class Subject {


    private List<Observer> observerList = new ArrayList<>();

    //添加观察者对象
    public void addObserver(Observer observer){
        observerList.add(observer);
    }

    //删除观察者对象
    public void removeObserver(Observer observer){
        observerList.remove(observer);
    }

    //通知观察者对象
    public void notifyObserver(){
        for (Observer observer : observerList) {
            observer.update();
        }
    }

}
